package com.hzdp.handles.rival.processors;

import com.hzdp.handles.rival.pipelines.DBPipeline;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;

/**
 * 美丽说 美妆
 * <p/>
 * Created by lyp on 15/12/15.
 */
public class MeiLiShuoProcessor implements PageProcessor {

    static final String START_URL = "http://www.mogujie.com/book/magic/51921";
    static final String LIST_URL_PATTERN = START_URL + "/\\d/.+";

    static final String CONTENT_URL_PATTERN = "http://shop.mogujie.com/detail/.+";


    @Override
    public void process(Page page) {
        if (page.getUrl().regex(CONTENT_URL_PATTERN).match()) {
            rivalData(page);
        } else {
            rivalLinks(page);
        }
    }

    private void rivalData(Page page) {
        //TODO
    }

    private void rivalLinks(Page page) {
        //TODO
    }

    @Override
    public Site getSite() {
        return Site.me().setRetryTimes(3).setSleepTime(100);
    }

    public static void main(String[] args) {
        Spider.create(new MeiLiShuoProcessor()).addUrl(START_URL).addPipeline(new DBPipeline(1,"香水")).run();
    }
}
